//
//  NSAttributedString+EmojiText.m
//  YunShouHu
//
//  Created by WangQiang on 16/7/12.
//  Copyright © 2016年 WangQiang. All rights reserved.
//

#import "NSAttributedString+EmojiText.h"
#import "EmojiAttachment.h"

@implementation NSAttributedString (EmojiText)
-(NSString *)encodeEmojiText{
    if(self.length <= 0) return @"";
    __block  NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:self];
    //倒叙替换的所以不影响
    [self enumerateAttribute:NSAttachmentAttributeName inRange:NSMakeRange(0, self.length) options:NSAttributedStringEnumerationReverse usingBlock:^(id  _Nullable value, NSRange range, BOOL * _Nonnull stop) {
        if (value) {
            EmojiAttachment *attach = (EmojiAttachment *)value;
            [string replaceCharactersInRange:range withString:attach.emoji.emojiEncoded];
        }
    }];
    return string.string;
}
@end
